import java.util.Date;
import java.text.DateFormat;
import java.util.Calendar;

import javax.swing.JFrame;
import javax.swing.JLabel;


@SuppressWarnings("serial")
public class Clock extends JFrame implements Runnable {
	
	private JFrame ventana;
	private JLabel hora;
	private int ms;

	public Clock(int ms){
		super();
		this.hora= new JLabel();
		this.ventana= new JFrame();
		this.ms=ms;
		
		ventana.add(hora);
		ventana.setSize(300,300);
		ventana.setVisible(true);
		
	}
		
	public void run() {
		while(true){
			try {
				Calendar cal= Calendar.getInstance();
				Date date= cal.getTime();
				DateFormat dateFormater= DateFormat.getTimeInstance();
				hora.setText(dateFormater.format(date));
				Thread.sleep(ms);
				ventana.repaint();
				
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}//run
	
	public static void main( String[] pars ) {
		Thread t1 = new Thread(new Clock(1));
		Thread t2 = new Thread(new Clock(5000));
		
		System.out.println( "Ahi va el reloj" );
		t1.start(); // Ejecuta t1.run()
		t2.start();
		
		try {
			t1.join(); // Espera hasta que acabe t1.run()
			t2.join();
		} catch( InterruptedException e ) { }
			System.out.println();
			System.out.println( "Fin del thread" );
		}
	
}
